import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Question9 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        
        int n = in.nextInt();
        int m = in.nextInt();
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();
        int x3 = in.nextInt();
        int y3 = in.nextInt();

        int ret = 0;

        // 找第一个
        // x 方向
        int distX1 = Math.min(Math.abs(x1 - x2), n - Math.abs(x1 - x2));
        int distY1 = Math.min(Math.abs(y1 - y2), m - Math.abs(y1 - y2));

        int dist1 = distX1 + distY1;

        // 找第二个
        int distX2 = Math.min(Math.abs(x3 - x2), n - Math.abs(x3 - x2));
        int distY2 = Math.min(Math.abs(y3 - y2), m - Math.abs(y3 - y2));

        int dist2 = distX2 + distY2;
        

        ret = dist1 + dist2;

        System.out.println(ret);
    }
}